﻿Public Class frmEstadoCaja

    Dim controller As New ControllerSigeco.controller_ventas()

    Private p_DatosDataSet As DataSet
    Public Property ds_Reporte() As DataSet
        Get
            Return p_DatosDataSet
        End Get
        Set(ByVal value As DataSet)
            p_DatosDataSet = value
        End Set
    End Property

    Private p_saldo_Anterior As Decimal
    Public Property SaldoAnterior() As Decimal
        Get
            Return p_saldo_Anterior
        End Get
        Set(ByVal value As Decimal)
            p_saldo_Anterior = value
        End Set
    End Property

    Private Sub frmClienteEstadoCuenta_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        dgAnterior.AutoGenerateColumns = False
        dgDatos.AutoGenerateColumns = False
        dgTotal.AutoGenerateColumns = False

        dtpFechaInicio.Value = New DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0)
        dtpFechaFin.Value = New DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59)
        GenerarDatos()

        Me.WindowState = FormWindowState.Maximized

    End Sub

    Private Sub GenerarDatos()

        Try

            Dim dsDatos As New DataSet
            dsDatos = controller.get_Caja_Movimientos_All(oiml.dbConn, dtpFechaInicio.Value, dtpFechaFin.Value, SaldoAnterior)

            If Not dsDatos Is Nothing Then

                If dsDatos.Tables.Count = 3 Then

                    ds_Reporte = dsDatos
                    dgAnterior.DataSource = dsDatos.Tables(0)
                    dgDatos.DataSource = dsDatos.Tables(1)
                    dgTotal.DataSource = dsDatos.Tables(2)

                Else

                    ds_Reporte = dsDatos
                    dgDatos.DataSource = dsDatos.Tables(0)
                    dgTotal.DataSource = dsDatos.Tables(1)

                End If

            End If

        Catch ex As Exception

        End Try

    End Sub


    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub

    Private Sub btnGenerar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerar.Click
        GenerarDatos()
    End Sub

    Private m_frmReporte As frmReportes
    Public Property frmRpts() As frmReportes
        Get
            Return m_frmReporte
        End Get
        Set(ByVal value As frmReportes)
            m_frmReporte = value
        End Set
    End Property

    Private Sub btnImprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImprimir.Click

        If frmRpts Is Nothing Then
            frmRpts = New frmReportes
            'frmRpts.MdiParent = Me
            frmRpts.tipo_Reporte = "CAJAMOV"
            frmRpts.ds_Reporte = ds_Reporte
            frmRpts.SaldoAnterior = SaldoAnterior
            frmRpts.ShowDialog()
        Else

            If Not frmRpts.Visible Then
                frmRpts = New frmReportes()
                'frmRpts.MdiParent = Me
                frmRpts.tipo_Reporte = "CAJAMOV"
                frmRpts.ds_Reporte = ds_Reporte
                frmRpts.SaldoAnterior = SaldoAnterior
                frmRpts.ShowDialog()
            Else
                frmRpts.tipo_Reporte = "CAJAMOV"
                frmRpts.ds_Reporte = ds_Reporte
                frmRpts.SaldoAnterior = SaldoAnterior
                frmRpts.Select()
                frmRpts.Activate()
            End If

        End If

    End Sub

End Class